
/* Author: Manfred Gschweidl */

using namespace std;

#include "Callback.h"

namespace globus_common {

Callback::Callback() {
	globus_mutex_init(&mutex, GLOBUS_NULL);
	globus_cond_init(&cond, GLOBUS_NULL);
	done = GLOBUS_FALSE;
}

Callback::~Callback() {
	globus_mutex_destroy(&mutex);
	globus_cond_destroy(&cond);
}

globus_bool_t Callback::isDone() {
	return done;
}

void Callback::setDone() {
	globus_mutex_lock(&mutex);
	done = GLOBUS_TRUE;
	globus_cond_broadcast(&cond);
	globus_mutex_unlock(&mutex);
}

void Callback::proceed() {
	globus_mutex_lock(&mutex);
	done = GLOBUS_FALSE;
	globus_mutex_unlock(&mutex);
}

void Callback::wait() {
	cout << "in wait" << endl;
	globus_mutex_lock(&mutex);
	cout << "10" << endl;
	while(!isDone()) {
		cout << "waiting..." << endl;
		globus_cond_wait(&cond, &mutex);
		cout << "11" << endl;
	}
	cout << "finished wait" << endl;
 	globus_mutex_unlock(&mutex);
}

}


